import {page, pageFunc} from "../common/PageBuilder";
import {BasePage, BasePageData} from "../common/core/BasePage";
import {UserPage} from "../common/partPages/UserPage";
import {QueryPage} from "../common/partPages/QueryPage";
import {waitForLogin} from "../../modules/userModule/managers/UserManager";
import {waitForDataLoad} from "../../modules/coreModule/managers/DataManager";
import {TaskInterface} from "../../modules/taskModule/TaskCommon";
import {DataLoader, field} from "../../modules/coreModule/data/DataLoader";
import {TaskIndexData} from "../../modules/taskModule/data/Task";
import {pageMgr} from "../../modules/coreModule/managers/PageManager";
import {RecruitPage} from "../recruit/RecruitPage";

class Data extends BasePageData {

	@field([TaskIndexData])
	list: TaskIndexData[] = TaskIndexData.testData();
}

@page("myApply", "我的报名")
export class MyApplyPage extends BasePage<Data> {

	public data = new Data();

	/**
	 * 部分页
	 */
	public userPage: UserPage = new UserPage();
	public queryPage: QueryPage =
		new QueryPage(this.loadData.bind(this));

	onLoad(e) {
		super.onLoad(e);
		this.queryPage.refresh();
	}

	/**
	 * 数据回调
	 */
	@waitForLogin
	@waitForDataLoad
	public async loadData(queryParams) {
		const res = await TaskInterface.GetParticTasks({
			...queryParams,
			sortTime: -1 // Desc
		})
		const list = res.tasks?.map(
			t => DataLoader.load(TaskIndexData, t));

		return list && this.setData({list});
	}

	@pageFunc
	public toRecruit() {
		pageMgr().push(RecruitPage).then();
	}
}
